
package com.javaleague.sesionUsuario;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.javaleague.persistencia.DAODeleteUser;
import java.io.IOException;

/**
 * @author TaixMiguel
 */
public class DeleteUser extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
        
        HttpSession session = request.getSession(true);
        Usuario user = (Usuario)session.getAttribute("usuario");
        if (user != null && request.getParameter("password") != null) {
            String pass = request.getParameter("password");

            if (DAODeleteUser.eliminarUsuario(user.getId(), user.getTokenUser(), pass, user.getNombre(), request.getRemoteAddr())) {
                HttpSession sesion = request.getSession();
                sesion.invalidate();
                response.sendError(200);
            } else
                response.sendError(608);
        } else
            response.sendError(403);
    }
    
    
        
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        processRequest(request, response);
    }
}